package com.lxl.exercise;

import java.util.*;

public class Demo1 {
    public List<List<String>> demo(String[] strings){
        Map<String,List<String>> map = new HashMap<>();
        for (String string : strings) {
            char[] chars = string.toCharArray();
            Arrays.sort(chars);
            String key = new String(chars);
            List<String> list = map.getOrDefault(key, new ArrayList<>());
            list.add(string);
            map.put(key, list);

        }
        return new ArrayList<>(map.values());
    }

    public static void main(String[] args) {
        String[] strs = {"eat", "tea", "tan", "ate", "nat", "bat"};
        Demo1 demo1 = new Demo1();
        List<List<String>> demo = demo1.demo(strs);
        demo.forEach(System.out::println);

    }
}
